<?php
require_once 'modules/service/commonService.php';

class LinksService extends CommonService {

    /**
     * @desc 链接服务层
     * @author liuhui 
     * @version 2009-7-3
     */
    
    /**
     * @desc 增加一个链接
     *
     */
    public function add (array $fields) {
        $fields = $this->checkFields($fields, Consts::FIELDS_LINKS());
        if (!$fields) {
            return null;
        }
        return $this->getDaoFactory()->getLinksDao()->add($fields);
    }

    public function update ($fields, $link_id) {
        $fields = $this->checkFields($fields, Consts::FIELDS_LINKS());
        if (!$fields || $this->filterParam($link_id) < 1) {
            return null;
        }
        return $this->getDaoFactory()->getLinksDao()->update($fields, $link_id);
    }

    public function get ($link_id) {
        if ($this->filterParam($link_id) < 1) {
            return null;
        }
        return $this->getDaoFactory()->getLinksDao()->get($link_id);
    }

    public function gets ($category_id, $offset = 0, $limit = 20) {
        if ($this->filterParam($category_id) < 1) {
            return null;
        }
        return $this->getDaoFactory()->getLinksDao()->gets($category_id, $offset, $limit);
    }

    public function delete ($link_id) {
        if ($this->filterParam($link_id) < 1) {
            return null;
        }
        return $this->getDaoFactory()->getLinksDao()->delete($link_id);
    }

    public function count ($category_id) {
        if ($this->filterParam($category_id) < 1) {
            return null;
        }
        return $this->getDaoFactory()->getLinksDao()->count($category_id);
    }

}
